package com.situ.javase.day5;

import java.util.Scanner;

import org.junit.Test;

public class OOPDemo {
	
	@Test
	public void test() {
		// 引用数据类型
		int[] array = new int[4];
		// Scanner scanner = new Scanner(System.in);
		// scanner.nextInt();
		Student student1 = new Student();
		student1.id = 1;
		student1.name = "张三";
		student1.age = 20;
		student1.className = "Java190703";
		student1.study();
		String name = student1.name;
		System.out.println(name);
		
		Student student2 = new Student();
		student2.id = 2;
		student2.name = "李四";
		student2.age = 23;
		student2.className = "UI";
		
		Teacher teacher = new Teacher();
		teacher.id = 1;
		teacher.name = "王五";
		teacher.salary = 10000;
		teacher.teach();
	}
	
	@Test
	public void test2() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生的数量");
		int count = scanner.nextInt();
		Student[] array = new Student[count];
		for (int i = 0; i < array.length; i++) {
			// 每次遍历构造一个学生对象
			Student student = new Student();
			System.out.println("请输入学生的id：");
			int id = scanner.nextInt();
			student.id = id;
			System.out.println("请输入学生的名字：");
			String name = scanner.next();
			student.name = name;
			
			// 将每次遍历生成的student对象放到数组对应下标的位置
			array[i]  = student;
		}
		
		for (int i = 0; i < array.length; i++) {
			// array[i]在等号右表表示：拿出数组下标存放对象
			Student student = array[i];
			System.out.println(student.id);
			System.out.println(student.name);
			System.out.println(student.age);// 0
			System.out.println(student.className);// null
		}
	}
	
	// argument 参数
	public static void main(String[] args) {
		// new的是无参构造方法
		Student student1 = new Student();
		student1.id = 1;
		student1.name = "张三";
		
		Student student = new Student(2, "lisit", 23, "Java1907");
		int id = student.id;
		System.out.println(id);
		System.out.println(student.id);
		System.out.println(student.name);
		System.out.println(student.age);
		System.out.println(student.className);
		System.out.println("-------");
		System.out.println(student.toString());
		//直接打印student对象，打印的就是toString()方法返回的字符串
		System.out.println(student);
	}
	
	
	@Test
	public void test55() {
		Student student = new Student();
		// 属性私有之后，外界不能直接访问
		// student.id = 12;
		// student.age = 200;
		student.setAge(223);
		student.setName("zhangsan");
		// int age = student.age;
		int age = student.getAge();
		System.out.println(age);
	}
	
}
